﻿--7 - Найти пап у которых есть 2 контакта

select [ID], [LastName], [Name]
from [MyFamily].[dbo].[Persons]
 join
 (select [fk_PersonID], Count(*) c from
  [MyFamily].[dbo].[Contact] group by [fk_PersonID] having Count(*) =2) a
  on ([MyFamily].[dbo].[Persons].ID = a.fk_PersonID)
where [ID] in (
select [fk_fatherID] 
from [MyFamily].[dbo].[Persons] 
where [fk_fatherID] is NOT NULL)



